package com.jswlw.controller.admin;

import com.jswlw.entity.biz.*;
import com.jswlw.schedule.TotalSchedule;
import com.jswlw.service.biz.*;
import com.jswlw.web.manager.SessionAdminManager;
import com.jswlw.controller.BaseController;
import com.jswlw.service.base.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.stream.Collectors;

@Controller
@RequestMapping("/")
public class IndexController extends BaseController {

    @Autowired
    MenuService menuService;
    @Autowired
    DevInfoService devInfoService;
    @Autowired
    DistributorService distributorService;
    @Autowired
    OrderInfoService orderInfoService;
    @Autowired
    BookInfoService bookInfoService;
    @Autowired
    FeedBackService feedBackService;
    @Autowired
    RepairInfoService repairInfoService;
    @Autowired
    TotalSchedule totalSchedule;

    /**
     * 用户后台主页
     *
     * @return
     */
    @RequestMapping("/")
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("menus", menuService.findMenu4Role(SessionAdminManager.getCurrentUser().getRoleId()));
        modelAndView.addObject("user", SessionAdminManager.getCurrentUser());
        modelAndView.setViewName("main");
        return modelAndView;
    }

    @RequestMapping("/total")
    public ModelAndView total() {
        ModelAndView modelAndView = new ModelAndView();
        if (totalSchedule.getTotalMap().isEmpty()) {
            totalSchedule.execute();
        }
        modelAndView.addAllObjects(totalSchedule.getTotalMap());
        modelAndView.setViewName("total");
        return modelAndView;
    }

    @RequestMapping("/map")
    public ModelAndView map() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("map");
        return modelAndView;
    }

    @RequestMapping("/mapDevList")
    @ResponseBody
    public ModelMap mapDevList() {
        DevInfo filter = new DevInfo();
        filter.setBindStatus(1);
        return this.successResult(devInfoService.queryList(filter));
    }
}
